using MicroMsg.Manager;
using System;
using System.Collections.Generic;
namespace MicroMsg.UI.Util
{
	public class SearchItem
	{
		public object mSerachObj;
		public string mStrKey;
		public int mNSearchType;
		private List<SearchKeyExInfo> mListKeyExInfo;
		public object mObjTag;
		public SearchItem(object serachObj, string strKey, int type, object objTag = null)
		{
			if (string.IsNullOrEmpty(strKey))
			{
				return;
			}
			this.mSerachObj = serachObj;
			this.mStrKey = this.filterEmj(strKey);
			this.mNSearchType = type;
			this.mObjTag = objTag;
			this.makeSearchExInfo();
		}
		private string filterEmj(string strCon)
		{
			EmojiManager instance = EmojiManager.GetInstance();
			if (!instance.IsHasEmojiCode(strCon))
			{
				return strCon;
			}
			string text = "";
			for (int i = 0; i < strCon.get_Length(); i++)
			{
				char c = strCon.get_Chars(i);
				if (-1 == instance.getEmojiPos(c))
				{
					text += c;
				}
			}
			return text;
		}
		public SearchMatchRange Match(string strContent)
		{
			if (!this.isInfoOk())
			{
				return null;
			}
			if (string.IsNullOrEmpty(strContent))
			{
				return new SearchMatchRange(-1, 0);
			}
			SearchMatchRange result;
			using (List<SearchKeyExInfo>.Enumerator enumerator = this.mListKeyExInfo.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SearchKeyExInfo current = enumerator.get_Current();
					if (current != null)
					{
						SearchMatchRange searchMatchRange = current.Match(ref strContent);
						if (searchMatchRange != null)
						{
							result = searchMatchRange;
							return result;
						}
					}
				}
				goto IL_5F;
			}
			return result;
			IL_5F:
			return null;
		}
		private void makeSearchExInfo()
		{
			if (string.IsNullOrEmpty(this.mStrKey))
			{
				return;
			}
			string text = this.mStrKey.ToLower();
			this.mListKeyExInfo = new List<SearchKeyExInfo>();
			if ((this.mNSearchType & 4) != 0)
			{
				this.mListKeyExInfo.Add(SearchKeyExInfo.MakeSearchKeyExInfo(ref text, SearchType.FirstPinyin));
			}
			if ((this.mNSearchType & 1) != 0)
			{
				this.mListKeyExInfo.Add(SearchKeyExInfo.MakeSearchKeyExInfo(ref text, SearchType.OriginContent));
			}
			if ((this.mNSearchType & 2) != 0)
			{
				this.mListKeyExInfo.Add(SearchKeyExInfo.MakeSearchKeyExInfo(ref text, SearchType.Pinyin));
			}
		}
		private bool isInfoOk()
		{
			return this.mListKeyExInfo != null && this.mSerachObj != null && !string.IsNullOrEmpty(this.mStrKey) && this.mNSearchType != 0;
		}
	}
}
